﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsAppTest.Dao;

namespace WinFormsAppTest
{
    public partial class FilesUpdateForm : Form
    {
        public int fileid;
        public string msg;
        public string house;
        public string contract;
        public string insure;
        public int userid;
        public string adminname;
        public int adminid;

        public FilesUpdateForm()
        {
            InitializeComponent();
        }

        public FilesUpdateForm(int fileid, string msg,
                              string house, string contract, string insure,
                              int userid, string adminname, int adminid)
        {
            this.fileid = fileid;
            this.msg = msg;
            this.house = house;
            this.contract = contract;
            this.insure = insure;
            this.userid = userid;
            this.adminname = adminname;
            this.adminid = adminid;
            InitializeComponent();
        }

        //public FilesUpdateForm(int uid, string uname, string upassword, string aname, int aid)
        //{
        //    username = uname;
        //    password = upassword;
        //    adminname = aname;
        //    adminid = aid;
        //    userid = uid;
        //    InitializeComponent();
        //}



        private void FilesUpdate_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                // 关闭进程
                Process.GetCurrentProcess().Kill();
            }
        }

        private void FilesUpdate_Load(object sender, EventArgs e)
        {
            MsgtextBox.Text = msg;
            HousetextBox.Text = house;
            ContracttextBox.Text = contract;
            InsuretextBox.Text = insure;
        }

        private void Exitbutton_Click(object sender, EventArgs e)
        {
            this.Hide();
            FilesForm f = new FilesForm(adminname, adminid);
            f.ShowDialog();
            this.Dispose();
        }

        private void OKbutton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(MsgtextBox.Text))
            {
                MessageBox.Show("添加员工基本信息不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(HousetextBox.Text))
            {
                MessageBox.Show("添加户口情况不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(ContracttextBox.Text))
            {
                MessageBox.Show("添加合同管理不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(InsuretextBox.Text))
            {
                MessageBox.Show("添加投保情况不能为空！");
            }
            else
            {
                //直接调用dao层进行添加
                FilesDao filesdao = new FilesDao();
                filesdao.UpdateFilesById(fileid, MsgtextBox.Text, HousetextBox.Text,
                                         ContracttextBox.Text, InsuretextBox.Text);
                MessageBox.Show("更新成功！");
                FilesForm f2 = new FilesForm(adminname, adminid);
                this.Hide();
                f2.ShowDialog();
                this.Dispose();

            }
        }

        private void Okbutton_Click(object sender, EventArgs e)
        {

            if (string.IsNullOrWhiteSpace(MsgtextBox.Text))
            {
                MessageBox.Show("添加员工基本信息不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(HousetextBox.Text))
            {
                MessageBox.Show("添加户口情况不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(ContracttextBox.Text))
            {
                MessageBox.Show("添加合同管理不能为空！");
            }
            else if (string.IsNullOrWhiteSpace(InsuretextBox.Text))
            {
                MessageBox.Show("添加投保情况不能为空！");
            }
            else
            {
                //直接调用dao层进行添加
                FilesDao filesdao = new FilesDao();
                filesdao.UpdateFilesById(fileid, MsgtextBox.Text, HousetextBox.Text,
                                         ContracttextBox.Text, InsuretextBox.Text);
                //MessageBox.Show("更新成功！" +fileid+ "  "+ MsgtextBox.Text +"  "+ HousetextBox.Text
                //                            +"  "+ ContracttextBox.Text+"  "+ InsuretextBox.Text);
                MessageBox.Show("更新成功！");
                FilesForm f2 = new FilesForm(adminname, adminid);
                if(adminid != 0)
                {
                    this.Hide();
                    f2.ShowDialog();
                    this.Dispose();
                }
                else
                {
                    this.Hide();
                    Form2 form2 = new Form2();
                    form2.ShowDialog();
                    this.Dispose();
                }
            }
        }
    }
}
